// import { useUserStore } from '@/stores/modules';
import axios from 'axios';

// create an axios instance
const instance = axios.create({
  //baseURL: import.meta.env.VITE_APP_API_BASE_PATH,
  baseURL: '',
  withCredentials: false,
  timeout: 30 * 60 * 1000
});

// request interceptor
instance.interceptors.request.use(
  config => {
    // const token = useUserStore().access_token;
    // if (token) {
    //   config.headers.Authorization = `Bearer ${token}`;
    // }
    return config;
  },
  error => {
    console.log(error);
    return Promise.reject(error);
  }
);

// response interceptor
instance.interceptors.response.use(
  response => {
    // if (response.data.code === 401) {
    //   //ElMessage.warning(response.data.msg)
    //   const userStore = useUserStore()
    //   userStore.Login()
    // }
    return response.data;
  },
  error => {
    console.log('err' + error);
    return Promise.reject(error.message);
  }
);

export default instance;